package cn.paul.wechatshop.controller;

import cn.paul.wechatshop.common.Const;
import cn.paul.wechatshop.dto.OrderDTO;
import cn.paul.wechatshop.exception.WechatshopException;
import cn.paul.wechatshop.service.IOrderMasterService;
import cn.paul.wechatshop.service.IPayService;
import com.google.common.collect.Maps;
import com.lly835.bestpay.model.PayResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @author 徐凌峰
 * @date 2017/12/30
 */
@Controller
@RequestMapping("pay")
public class PayController {
    @Autowired
    private IOrderMasterService iOrderMasterService;
    @Autowired
    private IPayService iPayService;

    @GetMapping("create")
    public ModelAndView create(String orderId, String returnUrl) {

        OrderDTO orderDTO = iOrderMasterService.findOne(orderId).getData();
        if (orderDTO == null) {
            throw new WechatshopException(Const.ResultEnum.ORDER_NOT_EXISTS);
        }
        PayResponse payResponse = iPayService.create(orderDTO);
        Map map = Maps.newHashMap();
        map.put("orderId", "111111");
        //发起支付
        return new ModelAndView("pay/create",map);
    }

}
